package com.codingapi.websocket.core.handler.netty;

import com.codingapi.websocket.core.util.ChannelUtil;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelOutboundHandlerAdapter;
import io.netty.channel.ChannelPromise;

/**
 * @author modificial
 * @date 2018/7/19
 * @company codingApi
 * @description 适配器
 */
public abstract class AbstractOutboundHandler extends ChannelOutboundHandlerAdapter {


    @Override
    public void disconnect(ChannelHandlerContext ctx, ChannelPromise promise) throws Exception {
        String id = ChannelUtil.getChannelCtxId(ctx);
        this.doDisconnect(id, ctx, promise);
    }

    @Override
    public void close(ChannelHandlerContext ctx, ChannelPromise promise) throws Exception {
        String id = ChannelUtil.getChannelCtxId(ctx);
        this.doClose(id, ctx, promise);
        super.close(ctx, promise);
    }


    public abstract void doDisconnect(String channelId, ChannelHandlerContext ctx, ChannelPromise promise) throws Exception;

    public abstract void doClose(String channelId, ChannelHandlerContext ctx, ChannelPromise promise) throws Exception;
}
